package com.settlement.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.settlement.system.common.result.PageResult;
import com.settlement.system.common.result.Result;
import com.settlement.system.model.entity.SysFileAudit;
import com.settlement.system.model.query.FileAuditPageQuery;
import com.settlement.system.model.vo.AuditVo;
import com.settlement.system.service.SysFileAuditService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 归档核销表 前端控制器
 * </p>
 *
 * @author huangrensen
 * @since 2023-08-05
 */
@Tag(name = "归档核销表")
@RestController
@RequestMapping("/api/v1/fileAudit")
@RequiredArgsConstructor
public class SysFileAuditController {

    private final SysFileAuditService fileAuditService;

    @Operation(summary = "标准核销单分页列表", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/page")
    public PageResult<SysFileAudit> getFileAuditPage(@ParameterObject FileAuditPageQuery queryParams) {
        Page<SysFileAudit> result = fileAuditService.getFileAuditPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "获取详情", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping(value = "/{auditId}/{billMonth}")
    public Result<AuditVo> getAuditForm(@Parameter(description = "核销单ID") @PathVariable String auditId, @Parameter(description = "账单月份") @PathVariable String billMonth) {
        AuditVo formData = fileAuditService.getAuditForm(auditId, billMonth);
        return Result.success(formData);
    }

    @Operation(summary = "获取标准订单详情", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping(value = "/order/{linkNo}/{fileAuditId}")
    public Result<?> getOrderDetail(@Parameter(description = "关联单号") @PathVariable String linkNo,
                                            @Parameter(description = "归档核销单ID") @PathVariable String fileAuditId) {
        return Result.success(fileAuditService.getOrderDetailList(fileAuditId, linkNo));
    }

    @Operation(summary = "获取标准账单详情", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping(value = "/bill/{linkNo}/{fileAuditId}")
    public Result<?> getBillDetail(@Parameter(description = "关联单号") @PathVariable String linkNo,
                                           @Parameter(description = "归档核销单ID") @PathVariable String fileAuditId) {
        return Result.success(fileAuditService.getBillDetail(fileAuditId, linkNo));
    }

    @Operation(summary = "已归核销单档调账处理功能", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping(value = "/antiAudit/{auditId}/{billMonth}")
    @PreAuthorize("@ss.hasPerm('sys:fileAudit:reCheck')")
    public Result<?> antiAudit(@Parameter(description = "核销单ID") @PathVariable String auditId, @Parameter(description = "账单月份") @PathVariable String billMonth) {
        fileAuditService.antiAudit(auditId, billMonth);
        return Result.success();
    }
}
